<script type="text/javascript" src="javascript/ajax/prototype.js"></script>
<script type="text/javascript">

  function getSubCategory(obj){
    var div_subcate = document.getElementById('subcategory_container');
    var category = document.getElementById('form_category_id_');
    var filter = "&filter=scy_category_id = '" + category.value + "'";
    var name = "&name=form[subcategory_id]";
    var url = "index.php?module=InnoForum&type=ajax&func=selector&ctrl=Sub_Category" + filter + name + genSession() ;
    div_subcate.innerHTML ="Loading...";
    new Ajax.Request(url, {
        method:'get',
        onSuccess: function(transport){
         var result = transport.responseText;
         div_subcate.innerHTML= result;
         }	   
      });
    
  }
  function genSession(){
    return '&r=' + Math.random(999);
  }
</script>
<form id="form1" name="form1" method="post" action="">
    <b>Search :</b> <input type="text" name="textfield" /><br/>
    <b>ประเภท</b>
    <div>
    <!--[selector_object_array_ex modname="InnoForum" 
        class="Category" 
        field="id" 
        displayField="name"  
        name="form[category_id]" 
        selectedValue=$form.category_id
        onChange="getSubCategory(this)"]-->
    </div>
    <div id='subcategory_container'>
      <!--[assign var='category_id' value=$form.category_id]-->
      <!--[if not empty($category_id)]-->
      <!--[selector_object_array_ex modname="InnoForum" 
        class="SubCategory" 
        field="id" 
        displayField="name"  
        name="form[subcategory_id]" 
        selectedValue=$form.subcategory_id
        where="scy_category_id = '$category_id'"
        ]-->
      <!--[else]-->
        <!--[* get table prefix for query where *]-->
        <!--[pnconfiggetvar name='prefix' assign=prefix]-->
        <!--[selector_object_array_ex modname="InnoForum" 
        class="SubCategory" 
        field="id" 
        displayField="name"  
        name="form[subcategory_id]" 
        selectedValue=$form.subcategory_id
        where="scy_category_id = (SELECT MIN(cty_id) FROM `$prefix`_innoforum_category)"
        ]-->
      <!--[/if]-->
    </div>
    <br />
    <input type="button" value="ค้นหา" /> 
  </form>
